package vn.sunnet.backviet01.game.coloa.human.enemy;

import org.anddev.andengine.engine.handler.physics.PhysicsHandler;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.opengl.texture.region.TextureRegion;

public class DoThuMagic extends Sprite{
	private long begin = 0;
	private float xCenter;
	private float yCenter;
	
	private boolean isAttack = false;
	private boolean isChecked = false;
	
	
	public DoThuMagic(float pX, float pY, TextureRegion pTextureRegion) {
		super(pX, pY, pTextureRegion);
		xCenter = pTextureRegion.getWidth() / 2;
		yCenter = pTextureRegion.getHeight() / 2;
		this.setScaleCenter(xCenter, yCenter);
	}

	public void reset() {
		super.reset();
		this.begin = 0;
		this.setScaleCenter(xCenter, yCenter);
		isAttack = false;
		isChecked = false;
	}
	
	public void onManagedUpdate(float pSecondsElapsed) {
		super.onManagedUpdate(pSecondsElapsed);
		if (getX() <= 100) {
			if (!isChecked) {
				isAttack = true;
				isChecked = true;
			}
		}
	}
	
	public long begin() {
		return begin;
	}
	
	public void beginUse() {
		begin = System.currentTimeMillis();
		
		PhysicsHandler handler = new PhysicsHandler(this);
		registerUpdateHandler(handler);
		handler.setVelocityX(-80);
	}
	
	public long timeLife() {
		return System.currentTimeMillis() - begin;
	}
	
	public float getCenterX() {
		return xCenter + this.getX();
	}
	
	public float getCenterY() {
		return yCenter + this.getY();
	}
	
	public void stopInfluence() {
		this.isAttack = false;
	}
	
	public boolean isAttack() {
		return isAttack;
	}
}
